﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using HYService.RabbitMQ;

using Api.Hub.Models;
using Api.Client.Proxy;

namespace Api.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            Task.Factory.StartNew(() =>
            {
                RabbitHub.Setup("exchange-demo", HYService.RabbitMQ.ExchangeType.Topic, "qabc", "123");
                RabbitHub.Route<MyMessage>("exchange-demo", "123", new MyMessage()
                {
                    Text = Guid.NewGuid().ToString(),
                    PublishTime = DateTime.Now
                });
            });

            int i = 0;
            while (i < 10)
            {
                Thread thread = new Thread(() =>
                {
                    var consumer = RabbitHub.Subscribe<MyMessage>("qabc", (message) =>
                    {
                        Console.WriteLine("当前时间：" + DateTime.Now + ",发布时间：" + message.PublishTime);
                        Thread.Sleep(10 * 60 * 1000);
                    }, true);
                });

                thread.Start();
                i++;
            }

            Console.ReadKey();
        }
    }
}
